package com.beamfield.controller.api.mb;

import com.alibaba.fastjson.JSONObject;
import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.MbBaseController;
import com.beamfield.enums.HttpResultEnum;
import com.beamfield.model.SystemDictionaryData;
import com.beamfield.modelVo.SystemDictionaryDataVo;
import com.beamfield.modelVo.TreeVo;
import com.beamfield.service.manage.sys.DictonaryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/mb_api/sys")
public class MbDictonaryController extends MbBaseController {

    @Resource
    private DictonaryService dictonaryService;

    @RequestMapping("/selData")
    @ResponseBody
    public ApiResult selData( HttpServletRequest req) {
        Long beam_id = super.getLogInfo(req).getBeamId();
        JSONObject body = super.getBody(req);
        if(body == null){
            return new ApiResult(HttpResultEnum.MIS_PARAM.getCode(), HttpResultEnum.MIS_PARAM.getMessage());
        }

        String code = body.getString("code");

        if(code == null){
            return new ApiResult(HttpResultEnum.EXCEPTION.getCode(), "code不能为空");
        }
        ApiResult apiResult = new ApiResult();
        List<SystemDictionaryDataVo> dicByCode = dictonaryService.getDicByCode(code, beam_id);
        apiResult.setResult(dicByCode);
        return apiResult;
    }

}
